package com.ruoyi.book.service.impl;

import com.ruoyi.book.domain.Book;
import com.ruoyi.book.domain.BorrowInfo;
import com.ruoyi.book.mapper.BorrowMapper;
import com.ruoyi.book.service.IBorrowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 书籍借阅Service业务层处理
 *
 * @author yaohui
 * @date 2024-05-08
 */
@Service
public class BorrowServiceImpl implements IBorrowService {
    @Autowired
    private BorrowMapper borrowMapper;


    /**
     * 借阅添加
     *
     * @param borrowInfo 借阅信息
     * @return 结果
     */
    @Override
    public int insertBorrow(BorrowInfo borrowInfo) {
        return borrowMapper.borrowBook(borrowInfo);
    }

    /**
     * 将书籍的状态改为归还中
     * @param num 书本编号
     */
    @Override
    public void returnOneBook(String num) {
        BorrowInfo borrowInfo = borrowMapper.selectByBookNum(num);
        borrowInfo.setState("1");
        borrowMapper.updateBorrow(borrowInfo);
    }

    /**
     * 将书籍的状态改为归还
     *
     * @param num 书本编号
     */
    @Override
    public void confirmReturnOneBook(String num) {
        BorrowInfo borrowInfo = borrowMapper.selectByBookNum(num);
        borrowInfo.setState("0");
        borrowMapper.updateBorrow(borrowInfo);
    }
}
